home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
User's Choice Windows CD
/
User's Choice Windows CD (CMS Software)(1993).iso
/
win_m_p
/
mwpropvw.zip
/
MEWLDEMO.C
< prev
next >
Wrap
C/C++ Source or Header
|
1992-01-25
|
53KB
|
1,767 lines
#if 0
#define MODELESSTEST
#define CTLCOLOR_TEST
#endif
/*===========================================================================*/
/* */
/* File : MEWLDEMO.C */
/* */
/* Purpose : General purpose demo of the MEWEL Window Library */
/* */
/* History : */
/* */
/* (C) Copyright 1989 Marc Adler/Magma Systems All Rights Reserved */
/*===========================================================================*/
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <limits.h>
#ifndef UNIX
#include <io.h>
#include <dos.h>
#endif
#include <windows.h>
#ifdef MEWEL
#define MAKE_X(n) (n * 1)
#define MAKE_Y(n) (n * 1)
#define CX_RECT(r) (r.right - r.left + 1)
#define CY_RECT(r) (r.bottom - r.top + 1)
#else
#define MAKE_X(n) (n * 8)
#define MAKE_Y(n) (n * 16)
#define CX_RECT(r) (r.right - r.left)
#define CY_RECT(r) (r.bottom - r.top)
#define VidSetBlinking(n)
#define WM_HELP (WM_USER + 100)
#endif
typedef long (PASCAL *TIMERPROC)();
#define ID_MENUBAR 10
#define ID_NOTEPAD 12
#define ID_ABOUT 98
#define ID_COMBOBOX 97
#define ID_EXIT 99
#define ID_LISTDEMO 200
#define ID_TIMEDEMO 201
#define ID_MOUSEDEMO 202
#define ID_MENUDEMO 203
#define ID_FILEDEMO 204
#define ID_EDITDEMO 205
#define ID_EXECDEMO 206
#define ID_CALCDEMO 207
#define ID_CHILDDEMO 208
#define ID_GRAPHICS 213
#define ID_TOGGLEEGA 214
#define ID_COMBODEMO 210
#define ID_STRING 100
#define ID_POS 101
#define ID_FRAME 102
#define ID_APPEND 103
#define ID_INSERT 104
#define ID_DELETE 105
#define ID_LISTBOX 106
#define ID_STOP 100
#define ID_START 101
#define ID_INTERVAL 105
#define ID_WORD50 300
#define ID_WRITE 301
#define ID_EXCEL 302
#define ID_124 303
#define ID_C52 304
#define ID_QUICKC 305
#define ID_QUICKBASIC 306
#define ID_PASCAL 307
#define ID_NEW 200
#define ID_OPEN 201
#define ID_SAVE 202
#define ID_SAVEAS 203
#define ID_HELP 299
#define ID_COPY 510
#define ID_CUT 511
#define ID_PASTE 512
#define ID_CLEAR 513
#define ID_GETLEN 520
#define ID_GETLINES 521
#define ID_GETHANDLE 522
#define IDM_MEMAVAIL 600
#define IDS_MAINTITLE 500
/*
Function declarations
*/
extern int PASCAL WinMain(HANDLE, HANDLE, LPSTR, int);
extern LONG FAR PASCAL MainWndProc(HWND,WORD,WORD,LONG);
extern LONG FAR PASCAL MsgWndProc(HWND,WORD,WORD,LONG);
extern LONG FAR PASCAL NotepadWndProc(HWND,WORD,WORD,LONG);
extern int FAR PASCAL ListboxDialogProc(HWND,WORD,WORD,DWORD);
extern int FAR PASCAL IntervalDlgProc(HWND,WORD,WORD,DWORD);
extern LONG FAR PASCAL TimerWndProc(HWND,WORD,WORD,LONG);
extern int FAR PASCAL ComboDialogProc(HWND,WORD,WORD,DWORD);
extern LONG FAR PASCAL PanelWndProc(HWND,WORD,WORD,LONG);
extern LONG FAR PASCAL CalcDlgProc(HWND,WORD,WORD,LONG);
extern int FAR PASCAL DlgProc(HWND,WORD,WORD,DWORD);
extern int FAR PASCAL IntervalDlgProc(HWND,WORD,WORD,DWORD);
extern BOOL InitApp(HANDLE);
extern void TimerDemo(void);
extern HMENU TimerMenuInit(void);
extern void NewInterval(HWND);
extern int AreTimersRunning(void);
extern void KillAllTimers(void);
extern int MouseDemo(void );
extern int PrintScrollbarValues(HWND,WORD,WORD,LONG);
extern void DoFloatingPopup(void);
extern void ComboDemo(void);
extern int NotePad(void );
extern int NotepadOpenFile(LPSTR);
extern void DOSEscape(void );
extern int Calculator(void );
extern void ShowNumber(HWND,DWORD);
extern DWORD CalcIt(DWORD,WORD,DWORD);
extern int BadCommand(void );
extern void ChildDemo(void );
extern void CreateChildren(HWND);
extern void TerminateChildDemo(void );
extern void GraphicsModeDemo(void );
extern void VideoModeDemo(void );
extern LONG memavail(void );
#ifdef PROPVIEW
extern int PASCAL PVWinMain(HANDLE, HANDLE, LPSTR, int);
extern HWND hDlgActive;
#endif
/*
Global Window Handles
*/
HWND hMain;
HWND hMsgWnd;
HWND hTimeWnd;
HWND hMouseWnd = NULL;
HWND hWndCalc = NULL;
#ifdef MODELESSTEST
HWND hWndListbox = NULL;
HWND hWndString;
#endif
int cxMsgWnd, cyMsgWnd;
int cxTimeWnd;
HANDLE hAppInstance = 0;
#define MM_SHOWTIME (WM_USER + 243)
int PASCAL WinMain(hInstance, hPrevInstance, lpszCmdLine, nCmdShow)
HANDLE hInstance, hPrevInstance;
LPSTR lpszCmdLine;
int nCmdShow;
{
MSG msg;
char szBuf[64];
HANDLE hAccel;
RECT r;
HDC hDC;
TEXTMETRIC tm;
static DWORD dwLastTick = 0L;
(void) lpszCmdLine;
VidSetBlinking(FALSE);
/*
Register the main window class.
*/
if (!hPrevInstance)
if (!InitApp(hInstance))
exit(1);
/*
Create the main window and set the main window procedure
*/
LoadString(hInstance, IDS_MAINTITLE, (LPSTR) szBuf, sizeof(szBuf));
hMain = CreateWindow("Mewldemo", /* class */
szBuf, /* title */
WS_OVERLAPPEDWINDOW | /* dwStyle */
WS_VSCROLL | WS_HSCROLL,
CW_USEDEFAULT,0, /* x,y,width,height */
CW_USEDEFAULT,0, /* x,y,width,height */
NULL, /* hParent */
NULL, /* hMenu */
hInstance, /* hInst */
0L); /* lpParam */
/*
Load in the accelerator table
*/
hAccel = LoadAccelerators(hInstance, (LPSTR) "Mewldemo");
/*
Get coordinate info to help us set up the message and time windows
*/
hDC = GetDC(hMain);
GetTextMetrics(hDC, (LPTEXTMETRIC) &tm);
GetClientRect(hMain, (LPRECT) &r);
ReleaseDC(hMain, hDC);
cyMsgWnd = (tm.tmHeight+tm.tmExternalLeading) +
(2*GetSystemMetrics(SM_CYBORDER)),
cxMsgWnd = 42 * tm.tmAveCharWidth + (2*GetSystemMetrics(SM_CXBORDER));
cxTimeWnd = LOWORD(GetTextExtent(hDC,"55:55:55",8)) +
(2*GetSystemMetrics(SM_CXBORDER));
/*
Create a child window to display the output messages.
*/
hMsgWnd = CreateWindow("MsgWnd", /* class */
NULL, /* title */
WS_CHILD | WS_BORDER | WS_VISIBLE, /* dwStyle */
0,
r.bottom - cyMsgWnd + 1,
42 * tm.tmAveCharWidth + (2*GetSystemMetrics(SM_CXBORDER)),
cyMsgWnd,
hMain, /* hParent */
NULL, /* hMenu */
hInstance, /* hInst */
0L); /* lpParam */
/*
Create a window for the clock
*/
hTimeWnd = CreateWindow("MsgWnd",
NULL,
WS_CHILD | WS_BORDER | WS_VISIBLE,
r.right,
r.bottom - cyMsgWnd + 1,
8 * tm.tmAveCharWidth + (2*GetSystemMetrics(SM_CXBORDER)),
cyMsgWnd,
hMain, /* hParent */
NULL, /* hMenu */
hInstance, /* hInst */
0L); /* lpParam */
/*
Show the window
*/
ShowWindow(hMain, nCmdShow);
UpdateWindow(hMain);
#if defined(PROPVIEW)
if (!PVWinMain(hInstance, hPrevInstance, lpszCmdLine, nCmdShow))
return FALSE;
#endif
/*
Main message loop
*/
for (;;)
{
/*
This is how you can do background processing
*/
while (!PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
DWORD dwTick;
dwTick = GetTickCount();
if (dwTick >= dwLastTick + 1000)
{
SendMessage(hTimeWnd, MM_SHOWTIME, 0, dwTick);
dwLastTick = dwTick;
}
}
if (msg.message == WM_QUIT)
break;
if (msg.message == WM_MOUSEMOVE && hMouseWnd)
{
POINT pt;
pt = MAKEPOINT(msg.lParam);
wsprintf(szBuf, "x=%3d, y=%3d", pt.y, pt.x);
hDC = GetDC(hMouseWnd);
GetClientRect(hMouseWnd, (LPRECT) &r);
FillRect(hDC, (LPRECT) &r, GetStockObject(LTGRAY_BRUSH));
TextOut(hDC, 0, 0, (LPSTR) szBuf, lstrlen(szBuf));
ReleaseDC(hMouseWnd, hDC);
}
if (hWndCalc && IsDialogMessage(hWndCalc, &msg))
continue;
#ifdef MODELESSTEST
if (hWndListbox && IsDialogMessage(hWndListbox, &msg))
continue;
#endif
#ifdef PROPVIEW
if(hDlgActive && IsDialogMessage(hDlgActive, (LPMSG) &msg))
continue;
#endif
if (!TranslateAccelerator(hMain, hAccel, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return 0;
}
/****************************************************************************/
/* */
/* Function : InitApp */
/* */
/* Purpose : Registers the window class */
/* */
/* Returns : */
/* */
/****************************************************************************/
BOOL InitApp(hInstance)
HANDLE hInstance;
{
HANDLE hClass;
PWNDCLASS pClass;
hClass = LocalAlloc(LPTR | LMEM_ZEROINIT, sizeof(WNDCLASS));
pClass = (PWNDCLASS) LocalLock(hClass);
pClass->hCursor = LoadCursor(NULL, IDC_ARROW);
pClass->hIcon = LoadIcon(NULL, IDI_APPLICATION);
pClass->lpszMenuName = "MainMenu";
pClass->lpszClassName = "Mewldemo";
pClass->hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
pClass->hInstance = hInstance;
pClass->style = CS_HREDRAW | CS_VREDRAW;
pClass->lpfnWndProc = MainWndProc;
if (!RegisterClass((LPWNDCLASS) pClass))
return FALSE;
pClass->lpszMenuName = (LPSTR) NULL;
pClass->lpszClassName = "MsgWnd";
pClass->hbrBackground = (HBRUSH) GetStockObject(LTGRAY_BRUSH);
pClass->lpfnWndProc = MsgWndProc;
if (!RegisterClass((LPWNDCLASS) pClass))
return FALSE;
/*
Register the notepad class
*/
pClass->lpszMenuName = (LPSTR) "NotePad";
pClass->lpszClassName = "NotePad";
pClass->lpfnWndProc = NotepadWndProc;
if (!RegisterClass((LPWNDCLASS) pClass))
return FALSE;
/*
Register the timer window
*/
pClass->lpszMenuName = (LPSTR) NULL;
pClass->lpszClassName = "Timer";
pClass->lpfnWndProc = TimerWndProc;
pClass->hbrBackground = (HBRUSH) GetStockObject(LTGRAY_BRUSH);
if (!RegisterClass((LPWNDCLASS) pClass))
return FALSE;
/*
Register the calculator window
*/
pClass->lpszClassName = "HexCalc";
pClass->lpfnWndProc = CalcDlgProc;
pClass->hbrBackground = (HBRUSH) COLOR_WINDOW + 1;
pClass->cbWndExtra = DLGWINDOWEXTRA;
if (!RegisterClass((LPWNDCLASS) pClass))
return FALSE;
LocalUnlock(hClass);
LocalFree(hClass);
hAppInstance = hInstance;
return TRUE; /* Initialization succeeded */
}
/****************************************************************************/
/* */
/* Function : MainWndProc */
/* */
/* Purpose : Window procedure for the main window. */
/* */
/* Returns : */
/* */
/****************************************************************************/
LONG FAR PASCAL MainWndProc(HWND hWnd, WORD message, WORD wParam, LONG lParam)
{
char buf[80];
FARPROC lpfn;
switch (message)
{
case WM_COMMAND :
switch (wParam)
{
case ID_LISTDEMO :
if (AreTimersRunning())
KillAllTimers();
#ifdef MODELESSTEST
if ((hWndListbox =
CreateDialog(hInstance,"ListDemoDlg",hMain,
(FARPROC) ListboxDialogProc)) != NULL)
{
ShowWindow(hWndListbox, SW_SHOW);
SetFocus(hWndListbox);
hWndString = GetDlgItem(hWndListbox, ID_STRING);
}
#else
lpfn = MakeProcInstance((FARPROC) ListboxDialogProc, hAppInstance);
DialogBox(hAppInstance, "ListDemoDlg", hMain, (FARPROC) lpfn);
FreeProcInstance(lpfn);
#endif
break;
case ID_CHILDDEMO:
ChildDemo();
break;
case ID_CALCDEMO :
Calculator();
break;
case ID_TIMEDEMO :
if (AreTimersRunning())
KillAllTimers();
TimerDemo();
break;
case ID_MOUSEDEMO:
if (hMouseWnd)
{
DestroyWindow(hMouseWnd);
hMouseWnd = NULL;
}
else
{
MouseDemo();
}
CheckMenuItem(GetMenu(hMain), ID_MOUSEDEMO,
hMouseWnd ? MF_CHECKED : MF_UNCHECKED);
break;
case ID_MENUDEMO:
DoFloatingPopup();
break;
case ID_EDITDEMO :
NotePad();
break;
case ID_COMBODEMO:
ComboDemo();
break;
case ID_WORD50 :
case ID_WRITE :
case ID_EXCEL :
case ID_124 :
case ID_C52 :
case ID_QUICKC :
case ID_QUICKBASIC :
case ID_PASCAL :
LoadString(hAppInstance, wParam+1000, (LPSTR) buf, sizeof(buf));
MessageBox(NULL, buf, "WM_COMMAND", MB_OK);
break;
case ID_ABOUT :
MessageBox(NULL,"MEWEL Window System\nMagma Systems\n(201) 912-0192",
"About MEWEL", MB_OK | MB_ICONASTERISK);
break;
case ID_EXIT :
PostQuitMessage(0);
break;
case ID_HELP :
dohelp:
MessageBox(hWnd,
"MEWEL Demonstration Program\nMagma Systems\n15 Bodwell Terrace\nMillburn, NJ 07041\n\
(201) 912-0192 (voice)\n(201) 912-0668 (BBS)\n(201) 912-0103 (FAX)",
"MEWLDEMO", MB_OK | MB_ICONASTERISK);
break;
}
break;
case WM_VSCROLL :
case WM_HSCROLL :
PrintScrollbarValues(hWnd, message, wParam, lParam);
break;
case WM_SIZE :
{
RECT r;
GetClientRect(hWnd, (LPRECT) &r);
MoveWindow(hMsgWnd, 0, r.bottom - cyMsgWnd+1, cxMsgWnd, cyMsgWnd, TRUE);
MoveWindow(hTimeWnd, cxMsgWnd, r.bottom - cyMsgWnd+1, cxTimeWnd, cyMsgWnd, TRUE);
break;
}
case WM_MENUSELECT :
{
int iLen;
RECT r;
HDC hDC;
/*
We trigger off of the WM_MENUSELECT message so that we
can print informative messages about each menu option.
*/
GetClientRect(hMsgWnd, (LPRECT) &r);
hDC = GetDC(hMsgWnd);
FillRect(hDC, (LPRECT) &r, GetStockObject(LTGRAY_BRUSH));
/*
If lParam was <-1,0>, then the user dismissed the menu, so
we just want to erase the previous help text from the
status window. If not, then idMenu contains a valid menu or
submenu identifier. Load the corresponding string from
the string table, and print it.
*/
if (LOWORD(lParam) != 0xFFFF || HIWORD(lParam) != 0)
{
if ((iLen = LoadString(hAppInstance, wParam, (LPSTR) buf, sizeof(buf))) > 0)
{
TextOut(hDC, 0, 0, buf, iLen);
}
}
ReleaseDC(hMsgWnd, hDC);
break;
}
/*
WM_HELP is a MEWEL-specific message which is sent when a
menu item withthe HELP attribute is clicked on.
*/
case WM_HELP :
goto dohelp;
#ifdef RAINBOW
case WM_PAINT :
{
PAINTSTRUCT ps;
HDC hDC;
RECT r;
HBRUSH hBr;
int i;
hDC = BeginPaint(hWnd, (LPPAINTSTRUCT) &ps);
GetClientRect(hWnd, (LPRECT) &r);
for (i = 0; i < 16; i++)
{
r.top = r.bottom = i;
hBr = CreateSolidBrush(AttrToRGB(i));
FillRect(hDC, (LPRECT) &r, hBr);
DeleteObject(hBr);
}
EndPaint(hWnd, (LPPAINTSTRUCT) &ps);
break;
}
#endif
default :
/* Call the default window procedure for the main window */
return DefWindowProc(hWnd, message, wParam, lParam);
}
return TRUE;
}
LONG FAR PASCAL MsgWndProc(HWND hWnd, WORD message, WORD wParam, LONG lParam)
{
switch (message)
{
case MM_SHOWTIME :
{
char szBuf[32];
HDC hDC;
lParam /= 1000L; /* convert millisecs to seconds */
wsprintf(szBuf, "%02d:%02d:%02d",
(int) (lParam / 3600L),
(int) (lParam % 3600L) / 60,
(int) (lParam % 3600L) % 60);
hDC = GetDC(hWnd);
TextOut(hDC, 0, 0, (LPSTR) szBuf, lstrlen(szBuf));
ReleaseDC(hWnd, hDC);
return TRUE;
}
default :
return DefWindowProc(hWnd, message, wParam, lParam);
}
}
/*==========================================================================*/
/* */
/* Function : ListDemo() */
/* */
/* Purpose : Code to implement the listbox demo */
/* */
/* Returns : */
/* */
/*==========================================================================*/
int FAR PASCAL ListboxDialogProc(HWND hDlg, WORD message, WORD wParam, DWORD lParam)
{
char szString[130];
int iPos;
int operation;
int iSel;
static BYTE szItemText[130];
static int nMovedItem = - 1;
#ifdef MODELESSTEST
static HBRUSH hBlueBrush = 0;
#endif
switch (message)
{
case WM_INITDIALOG :
CheckRadioButton(hDlg, ID_APPEND, ID_DELETE, ID_APPEND);
#ifdef MODELESSTEST
if (!hBlueBrush)
{
hBlueBrush = CreateSolidBrush(RGB(0, 0, 255));
SetWindowsCompatibility(WC_SEND_WMCTLCOLOR);
}
#endif
return TRUE;
case WM_COMMAND :
switch (wParam)
{
case ID_INSERT :
case ID_DELETE :
case ID_APPEND :
CheckRadioButton(hDlg, ID_APPEND, ID_DELETE, wParam);
break;
case IDOK :
/*
The user pressed the OK button. We want to get the string
that is to be inserted as well as the position.
*/
GetDlgItemText(hDlg, ID_STRING, (LPSTR) szString, sizeof(szString));
iPos = GetDlgItemInt(hDlg, ID_POS, NULL, TRUE);
/*
Determine the operation to perform
*/
operation = 0;
if (IsDlgButtonChecked(hDlg, ID_APPEND))
operation = LB_ADDSTRING;
else if (IsDlgButtonChecked(hDlg, ID_INSERT))
operation = LB_INSERTSTRING;
else if (IsDlgButtonChecked(hDlg, ID_DELETE))
operation = LB_DELETESTRING;
if (operation)
{
SendDlgItemMessage(hDlg, ID_LISTBOX, operation, iPos,
(DWORD) (LPSTR) szString);
MessageBox(hMain, szString, "Completed", MB_OK | MB_ICONEXCLAMATION);
}
break;
case IDCANCEL :
EndDialog(hDlg, 0);
break;
case ID_LISTBOX :
switch (HIWORD(lParam))
{
case LBN_SELCHANGE :
if (nMovedItem < 0)
return FALSE;
iSel = (int) SendDlgItemMessage(hDlg,ID_LISTBOX,LB_GETCURSEL,0,0L);
SendDlgItemMessage(hDlg,ID_LISTBOX,LB_DELETESTRING,nMovedItem,0L);
SendDlgItemMessage(hDlg,ID_LISTBOX,LB_INSERTSTRING,iSel,
(DWORD) (BYTE far *) szItemText);
nMovedItem = iSel;
break;
}
return FALSE;
}
return TRUE;
#ifdef MODELESSTEST
case WM_SETFOCUS :
SetFocus(GetDlgItem(hDlg, ID_STRING));
return TRUE;
case WM_CTLCOLOR :
if (HIWORD(lParam) == CTLCOLOR_EDIT)
{
HBRUSH hBrush = hBlueBrush;
SetTextColor(wParam, RGB(0, 255, 255)); // cyan fore
SetBkColor(wParam, RGB(0, 0, 255)); // blue background
return hBrush;
}
else
return GetStockObject(WHITE_BRUSH);
case WM_CLOSE :
hWndListbox = NULL;
DestroyWindow(hDlg);
return TRUE;
#endif
}
return FALSE;
}
/*===========================================================================*/
/* */
/* File : MOVETEST.C */
/* */
/* Purpose : Demo of child windows. Included moving, resizing, and clipping */
/* */
/* History : */
/* */
/* (C) Copyright 1989 Marc Adler/Magma Systems All Rights Reserved */
/*===========================================================================*/
extern LONG FAR PASCAL PanelWndProc(HWND, WORD, WORD, LONG);
HWND hPanel1, hPanel2, hPanel3;
static PSTR pszChildMsg = (PSTR)
"You can move (drag the caption) or resize (drag lower-right corner) \
any of the 3 child windows.\n You can press the arrow keys to scroll \
the panels. This also demonstrates MEWEL clipping sibling windows.";
VOID ChildDemo(VOID)
{
HANDLE hMemory;
PWNDCLASS pWndClass;
TerminateChildDemo();
MessageBox(hMain, pszChildMsg, "Child Demo", MB_OK);
hMemory = LocalAlloc(LPTR | LMEM_ZEROINIT, sizeof(WNDCLASS));
pWndClass = (PWNDCLASS) LocalLock(hMemory);
pWndClass->hCursor = LoadCursor(NULL, IDC_ARROW);
pWndClass->hIcon = LoadIcon(NULL, IDI_APPLICATION);
pWndClass->lpszMenuName = NULL;
pWndClass->lpszClassName = "Panel";
pWndClass->lpfnWndProc = PanelWndProc;
pWndClass->cbWndExtra = sizeof(HBRUSH);
RegisterClass(pWndClass);
LocalUnlock(hMemory);
LocalFree(hMemory);
hPanel1=CreateWindow("Panel", /* class */
"Panel1", /* title */
WS_BORDER | WS_CHILD |
WS_SYSMENU | WS_CAPTION | WS_MINIMIZEBOX | WS_MAXIMIZEBOX |
WS_VSCROLL | WS_HSCROLL | WS_THICKFRAME |
WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
MAKE_X(4), MAKE_Y(3),
MAKE_X(30), MAKE_Y(14), /* x,y,width,height */
hMain, /* hParent */
1, /* id */
hAppInstance, /* hInst */
0L); /* lpParam */
SetWindowWord(hPanel1, 0, CreateSolidBrush(RGB(255, 0, 0)));
CreateChildren(hPanel1);
hPanel2=CreateWindow("Panel", /* class */
"Panel2", /* title */
WS_BORDER | WS_CHILD |
WS_SYSMENU | WS_CAPTION | WS_MINIMIZEBOX | WS_MAXIMIZEBOX |
WS_VSCROLL | WS_HSCROLL | WS_THICKFRAME |
WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
MAKE_X(24), MAKE_Y(6),
MAKE_X(30), MAKE_Y(14), /* x,y,width,height */
hMain, /* hParent */
2, /* id */
hAppInstance, /* hInst */
0L); /* lpParam */
SetWindowWord(hPanel2, 0, CreateSolidBrush(RGB(255, 0, 255)));
CreateChildren(hPanel2);
hPanel3=CreateWindow("Panel", /* class */
"Panel3", /* title */
WS_BORDER | WS_CHILD |
WS_SYSMENU | WS_CAPTION | WS_MINIMIZEBOX | WS_MAXIMIZEBOX |
WS_VSCROLL | WS_HSCROLL | WS_THICKFRAME |
WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
MAKE_X(44), MAKE_Y(9),
MAKE_X(30), MAKE_Y(14), /* x,y,width,height */
hMain, /* hParent */
3, /* id */
hAppInstance, /* hInst */
0L); /* lpParam */
SetWindowWord(hPanel3, 0, CreateSolidBrush(RGB(0, 0, 255)));
CreateChildren(hPanel3);
/*
Show the window
*/
ShowWindow(hPanel1, SW_SHOW);
ShowWindow(hPanel2, SW_SHOW);
ShowWindow(hPanel3, SW_SHOW);
BringWindowToTop(hPanel1);
SetFocus(hPanel1);
CheckMenuItem(GetMenu(hMain), ID_CHILDDEMO, MF_CHECKED);
}
#ifdef MEWEL
#define SCROLL_AMT 1
#else
#define SCROLL_AMT 16
#endif
LONG FAR PASCAL PanelWndProc(HWND hWnd, WORD message, WORD wParam, LONG lParam)
{
switch (message)
{
#if 0
case WM_MOUSEACTIVATE :
BringWindowToTop(hWnd);
return MA_ACTIVATEANDEAT;
#endif
case WM_KEYDOWN :
switch (wParam)
{
case VK_DOWN:
ScrollWindow(hWnd, 0, SCROLL_AMT, (LPRECT) NULL, (LPRECT) NULL);
break;
case VK_UP :
ScrollWindow(hWnd, 0, -SCROLL_AMT, (LPRECT) NULL, (LPRECT) NULL);
break;
case VK_LEFT:
ScrollWindow(hWnd, -SCROLL_AMT, 0, (LPRECT) NULL, (LPRECT) NULL);
break;
case VK_RIGHT:
ScrollWindow(hWnd, SCROLL_AMT, 0, (LPRECT) NULL, (LPRECT) NULL);
break;
case VK_HOME:
ScrollWindow(hWnd, -SCROLL_AMT, -SCROLL_AMT, (LPRECT) NULL, (LPRECT) NULL);
break;
case VK_PRIOR:
ScrollWindow(hWnd, SCROLL_AMT, -SCROLL_AMT, (LPRECT) NULL, (LPRECT) NULL);
break;
case VK_END :
ScrollWindow(hWnd, -SCROLL_AMT, SCROLL_AMT, (LPRECT) NULL, (LPRECT) NULL);
break;
case VK_NEXT:
ScrollWindow(hWnd, SCROLL_AMT, SCROLL_AMT, (LPRECT) NULL, (LPRECT) NULL);
break;
}
return TRUE;
case WM_CLOSE :
if (hWnd == hPanel1)
hPanel1 = NULL;
else
if (hWnd == hPanel2)
hPanel2 = NULL;
else
if (hWnd == hPanel3)
hPanel3 = NULL;
DeleteObject((HBRUSH) GetWindowWord(hWnd, 0));
DestroyWindow(hWnd);
if (!hPanel1 && !hPanel2 && !hPanel3)
CheckMenuItem(GetMenu(hMain), ID_CHILDDEMO, MF_UNCHECKED);
break;
case WM_ERASEBKGND :
{
RECT r;
GetClientRect(hWnd, (LPRECT) &r);
FillRect((HDC) wParam, (LPRECT) &r, (HBRUSH) GetWindowWord(hWnd, 0));
return TRUE;
}
case WM_CTLCOLOR :
if (HIWORD(lParam) == CTLCOLOR_EDIT || HIWORD(lParam) == CTLCOLOR_STATIC)
{
HBRUSH hBr = (HBRUSH) GetWindowWord(hWnd, 0);
LOGBRUSH lb;
GetObject(hBr, sizeof(lb), (LPSTR) &lb);
SetBkColor((HDC) wParam, lb.lbColor);
return hBr;
}
else
return DefWindowProc(hWnd, message, wParam, lParam);
default :
/* Call the default window procedure for the main window */
return DefWindowProc(hWnd, message, wParam, lParam);
}
return FALSE;
}
struct childinfo
{
char *szClass;
char *szTitle;
int x, y, cx, cy;
int id;
} ChildInfo[] =
{
{ "Static", "Business1:",1, 0,15,1, 24 } ,
{ "Edit", NULL, 20, 0,45,1, 25 },
{ "Static", "Business2:",1, 2,15,1, 24 } ,
{ "Edit", NULL, 20, 2,45,1, 25 },
{ "Static", "Business3", 1, 4,15,1, 24 } ,
{ "Edit", NULL, 20, 4,45,1, 25 },
{ "Static", "Business4", 1, 6,15,1, 24 } ,
{ "Edit", NULL, 20, 6,45,1, 25 } ,
{ "Static", "Business5", 1, 8,15,1, 24 } ,
{ "Edit", NULL, 20, 8,45,1, 25 },
};
VOID CreateChildren(HWND hParent)
{
struct childinfo *pCI;
int i;
DWORD dwStyle;
RECT r;
GetClientRect(hParent, &r);
for (i = 0; i < sizeof(ChildInfo)/sizeof(ChildInfo[0]); i++)
{
pCI = &ChildInfo[i];
if (i & 0x01)
{
dwStyle = ES_LEFT | WS_BORDER;
}
else
{
dwStyle = SS_LEFT;
}
CreateWindow(pCI->szClass,
pCI->szTitle,
dwStyle | WS_VISIBLE | WS_CHILD,
MAKE_X(pCI->x),
MAKE_Y(pCI->y),
MAKE_X(pCI->cx),
MAKE_Y(pCI->cy),
hParent, /* hParent */
pCI->id, /* hMenu */
hAppInstance, /* hInst */
0L); /* lpParam */
}
CreateWindow("Button",
"Push Me!",
WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON,
MAKE_X(1),
(r.bottom-MAKE_Y(1)),
MAKE_X(10),
MAKE_Y(1),
hParent, /* hParent */
100, /* hMenu */
hAppInstance, /* hInst */
0L); /* lpParam */
}
VOID TerminateChildDemo(VOID)
{
if (hPanel1)
SendMessage(hPanel1, WM_CLOSE, 0, 0L);
if (hPanel2)
SendMessage(hPanel2, WM_CLOSE, 0, 0L);
if (hPanel3)
SendMessage(hPanel3, WM_CLOSE, 0, 0L);
CheckMenuItem(GetMenu(hMain), ID_CHILDDEMO, MF_UNCHECKED);
}
/*========================================================================*/
/* */
/* SCRLDEMO.C - demonstration of the usage of scroll bars.... */
/* */
/*========================================================================*/
int PrintScrollbarValues(HWND hWnd, WORD message, WORD wParam, LONG lParam)
{
char *pszMsg;
char buf[80];
int nCode;
int minpos, maxpos, currpos;
HDC hDC;
HBRUSH hBrush;
RECT r;
(void) lParam;
nCode = (message == WM_HSCROLL) ? SB_HORZ : SB_VERT;
currpos = GetScrollPos(hWnd, nCode);
GetScrollRange(hWnd, nCode, &minpos, &maxpos);
switch (wParam)
{
case SB_LINEUP :
SetScrollPos(hWnd, nCode, max(currpos-1, minpos), TRUE);
currpos = GetScrollPos(hWnd, nCode);
pszMsg = "SB_LINEUP";
break;
case SB_LINEDOWN :
SetScrollPos(hWnd, nCode, min(currpos+1, maxpos), TRUE);
currpos = GetScrollPos(hWnd, nCode);
pszMsg = "SB_LINEDOWN";
break;
case SB_PAGEUP :
SetScrollPos(hWnd, nCode, max(currpos-10, minpos), TRUE);
currpos = GetScrollPos(hWnd, nCode);
pszMsg = "SB_PAGEUP";
break;
case SB_PAGEDOWN :
SetScrollPos(hWnd, nCode, min(currpos+10, maxpos), TRUE);
currpos = GetScrollPos(hWnd, nCode);
pszMsg = "SB_PAGEDOWN";
break;
case SB_TOP :
pszMsg = "SB_TOP";
goto do_it;
case SB_BOTTOM :
pszMsg = "SB_BOTTOM";
goto do_it;
case SB_THUMBTRACK :
pszMsg = "SB_THUMBTRACK";
goto do_it;
case SB_THUMBPOSITION :
pszMsg = "SB_THUMBPOSITION";
goto do_it;
case SB_ENDSCROLL :
pszMsg = "SB_ENDSCROLL";
do_it:
currpos = GetScrollPos(hWnd, nCode);
break;
}
wsprintf(buf, "Msg [%s] Pos [%3d] %3d%% ",
(LPSTR) pszMsg, currpos, currpos * 100 / maxpos);
hDC = GetDC(hMsgWnd);
hBrush = CreateSolidBrush(RGB(0, 128, 128));
GetClientRect(hMsgWnd, (LPRECT) &r);
FillRect(hMsgWnd, (LPRECT) &r, hBrush);
DeleteObject(hBrush);
SetTextColor(hDC, RGB(0, 0, 128));
SetBkColor(hDC, RGB(0, 128, 128));
TextOut(hDC, 0, 0, (LPSTR) buf, lstrlen(buf));
ReleaseDC(hMsgWnd, hDC);
return TRUE;
}
/**************************************************************************/
/* */
/* TIMER DEMO */
/* */
/**************************************************************************/
#define NUMTIMERS 4
HWND hTimerWnd[NUMTIMERS];
extern LONG FAR PASCAL TimerWndProc(HWND, WORD, WORD, LONG);
VOID TimerDemo(VOID)
{
int i;
HWND hWnd;
HMENU hMenu;
char title[16];
HDC hDC;
TEXTMETRIC tm;
int cx, cy;
MessageBox(hMain,
"The timer strings will occasionally overwrite the child windows.\nTHIS IS NOT A BUG.",
"Heed this", MB_OK | MB_ICONEXCLAMATION);
hDC = GetDC(hMain);
GetTextMetrics(hDC, (LPTEXTMETRIC) &tm);
cx = LOWORD(GetTextExtent(hDC, "555555555555", 12)) +
(2 * GetSystemMetrics(SM_CXBORDER));
cy = (tm.tmHeight + tm.tmExternalLeading) +
GetSystemMetrics(SM_CYCAPTION) +
GetSystemMetrics(SM_CYMENU) +
(2 * GetSystemMetrics(SM_CYBORDER));
ReleaseDC(hMain, hDC);
for (i = 1; i <= NUMTIMERS; i++)
{
wsprintf(title, "Timer %d", i);
hWnd = hTimerWnd[i-1] =
CreateWindow("Timer", /* class */
title, /* title */
WS_CAPTION | WS_BORDER | WS_CLIPCHILDREN |
WS_CLIPSIBLINGS | WS_VISIBLE,
((i-1) % 2) ? MAKE_X(50) : MAKE_X(20),
MAKE_Y((((i-1) / 2) + 1) * 6),
cx, cy,
hMain, /* hParent */
NULL, /* hMenu */
hAppInstance, /* hInst */
0L); /* lpParam */
hMenu = TimerMenuInit();
SetMenu(hWnd, hMenu);
DrawMenuBar(hWnd);
SetTimer(hWnd, i, i*1000, (FARPROC) NULL);
}
ShowWindow(hMain, SW_SHOW);
SetFocus(hTimerWnd[0]);
}
/*
This function tests the CreateMenu and ChangeMenu functions. We could
have loaded the menu fromt he resource file, but this shows how to
create a menu dynamically.
*/
HMENU TimerMenuInit()
{
HMENU hMenu, hPop;
/*
Create the menu bar
*/
hMenu = CreateMenu();
/*
Create a pulldown
*/
hPop = CreateMenu();
ChangeMenu(hPop, 0, "&Stop", ID_STOP, MF_APPEND);
ChangeMenu(hPop, 0, "&Interval", ID_INTERVAL, MF_APPEND);
ChangeMenu(hPop, 0, "E&xit", ID_EXIT, MF_APPEND);
/*
Attach each of the pulldowns to their corresponding menubar entries
*/
ChangeMenu(hMenu, 0, "&Timer", hPop, MF_POPUP | MF_APPEND);
return hMenu;
}
LONG FAR PASCAL TimerWndProc(HWND hWnd, WORD msg, WORD wParam, LONG lParam)
{
char szTime[80];
int i;
HDC hDC;
switch (msg)
{
case WM_TIMER :
wsprintf(szTime, "%ld", GetTickCount());
hDC = GetDC(hWnd);
TextOut(hDC, 0, 0, szTime, lstrlen(szTime));
ReleaseDC(hWnd, hDC);
MessageBeep(0);
return TRUE;
case WM_CHAR :
if (wParam == VK_TAB)
{
for (i = 1; i <= NUMTIMERS; i++)
if (hTimerWnd[i-1] == hWnd)
{
SetFocus(hTimerWnd[ (i == NUMTIMERS) ? 0 : i ]);
return TRUE;
}
}
break;
case WM_SETFOCUS :
BringWindowToTop(hWnd);
return DefWindowProc(hWnd, msg, wParam, lParam);
case WM_COMMAND :
switch (wParam)
{
case ID_EXIT :
case ID_STOP :
for (i = 1; i <= NUMTIMERS; i++)
if (hTimerWnd[i-1] == hWnd)
{
KillTimer(hWnd, i);
ModifyMenu(GetMenu(hWnd),
ID_STOP,
MF_BYCOMMAND | MF_STRING,
ID_START, "Start");
}
if (wParam == ID_EXIT)
{
/*
Setting focus to a non-timer window will eliminate the
situation where DestroyWindow(), detecting that the
window with the focus is being destroyed, sets the focus
to the next timer window (which will only be destroyed
in the next interation of the for loop). This will speed
up the process of destruction.
*/
SetFocus(hMain);
for (i = 1; i <= NUMTIMERS; i++)
{
DestroyWindow(hTimerWnd[i-1]);
hTimerWnd[i-1] = NULL;
}
}
break;
case ID_START:
for (i = 1; i <= NUMTIMERS; i++)
if (hTimerWnd[i-1] == hWnd)
{
SetTimer(hWnd, i, i*1000, (FARPROC) NULL);
ModifyMenu(GetMenu(hWnd),
ID_START,
MF_BYCOMMAND | MF_STRING,
ID_STOP, "Stop");
}
break;
case ID_INTERVAL :
NewInterval(hWnd);
break;
}
return TRUE;
default :
return DefWindowProc(hWnd, msg, wParam, lParam);
}
return TRUE;
}
VOID NewInterval(HWND hWnd)
{
int i, tid;
int interval;
FARPROC lpfn;
for (i = 1; i <= NUMTIMERS; i++)
if (hTimerWnd[i-1] == hWnd)
{
tid = i;
break;
}
lpfn = MakeProcInstance(IntervalDlgProc, hAppInstance);
if ((interval = DialogBox(hAppInstance, "IntervalDlg", hWnd, lpfn)) != IDCANCEL)
{
KillTimer(hWnd, tid);
SetTimer(hWnd, tid, interval, (FARPROC) NULL);
}
FreeProcInstance(lpfn);
}
int FAR PASCAL IntervalDlgProc(HWND hDlg, WORD msg, WORD wParam, DWORD lParam)
{
char szInterval[80];
(void) lParam;
switch (msg)
{
case WM_INITDIALOG :
return TRUE;
case WM_COMMAND :
if (wParam == IDCANCEL)
EndDialog(hDlg, IDCANCEL);
else if (wParam == IDOK)
{
GetDlgItemText(hDlg,ID_INTERVAL, (LPSTR)szInterval,sizeof(szInterval));
EndDialog(hDlg, atoi(szInterval));
}
return TRUE;
default :
return FALSE;
}
}
int AreTimersRunning(VOID)
{
return hTimerWnd[0];
}
VOID KillAllTimers(VOID)
{
SendMessage(hTimerWnd[0], WM_COMMAND, ID_EXIT, 0L);
}
/**************************************************************************/
/* */
/* MOUSE DEMO */
/* */
/**************************************************************************/
int MouseDemo(VOID)
{
HDC hDC;
TEXTMETRIC tm;
if (!GetSystemMetrics(SM_MOUSEPRESENT))
{
MessageBox(NULL, "You must have a mouse to run this demo.",
"Error",MB_OK);
return FALSE;
}
hDC = GetDC(hMain);
GetTextMetrics(hDC, (LPTEXTMETRIC) &tm);
hMouseWnd = CreateWindow("MsgWnd", /* class */
"Mouse", /* title */
WS_BORDER | WS_CHILD,
MAKE_X(30),
MAKE_Y(10),
LOWORD(GetTextExtent(hDC, "x=555, y=555", 12)) +
2*GetSystemMetrics(SM_CXBORDER),
(tm.tmHeight + tm.tmExternalLeading) +
2*GetSystemMetrics(SM_CYBORDER),
hMain, /* hParent */
NULL, /* id */
hAppInstance, /* hInst */
0L); /* lpParam */
ReleaseDC(hMain, hDC);
ShowWindow(hMouseWnd, SW_SHOW);
UpdateWindow(hMouseWnd);
return TRUE;
}
/**********************************************************************
* HEXCALC.C
*
* Converted to Mewel by Sal Ricciardi of PC Magazine
*
**********************************************************************/
DWORD CalcIt (DWORD dwFirstNum, WORD nOperation, DWORD dwNum);
VOID ShowNumber (HWND hWnd, DWORD dwNumber);
int Calculator(VOID)
{
if (hWndCalc)
{
BringWindowToTop(hWndCalc);
SetFocus(hWndCalc);
return TRUE;
}
MessageBox(hMain,
"The Calculator is a POPUP window, and will stay in front of all other \
non-popup windows (like the notepad).",
"Note", MB_OK);
if ((hWndCalc = CreateDialog(hAppInstance, "HexCalc", 0, (FARPROC) NULL)) != NULL)
{
ShowWindow(hWndCalc, SW_SHOW);
UpdateWindow(hWndCalc);
SetFocus(hWndCalc);
}
else
{
MessageBox(hMain, "Could not load calculator", "Error", MB_OK);
}
return TRUE;
}
VOID ShowNumber(HWND hWnd, DWORD dwNumber)
{
char szBuffer[20] ;
SetDlgItemText(hWnd, VK_ESCAPE,
strupr(ltoa(dwNumber, szBuffer, 16))) ;
}
DWORD CalcIt(DWORD dwFirstNum, WORD nOperation, DWORD dwNum)
{
switch (nOperation)
{
case '=' : return dwNum ;
case '+' : return dwFirstNum + dwNum ;
case '-' : return dwFirstNum - dwNum ;
case '*' : return dwFirstNum * dwNum ;
case '&' : return dwFirstNum & dwNum ;
case '|' : return dwFirstNum | dwNum ;
case '^' : return dwFirstNum ^ dwNum ;
case '<' : return dwFirstNum << dwNum ;
case '>' : return dwFirstNum >> dwNum ;
case '/' : return dwNum ? dwFirstNum / dwNum : ULONG_MAX ;
case '%' : return dwNum ? dwFirstNum % dwNum : ULONG_MAX ;
default : return 0L ;
}
}
LONG FAR PASCAL CalcDlgProc(HWND hWnd, WORD iMessage, WORD wParam, LONG lParam)
{
static BOOL bNewNumber = TRUE ;
static DWORD dwNumber, dwFirstNum ;
static short nOperation = '=' ;
HWND hButton ;
(void) lParam;
switch (iMessage)
{
case WM_KEYDOWN: /* left arrow --> backspace */
if (wParam != VK_LEFT)
break ;
wParam = VK_BACK ;
/* fall through */
case WM_CHAR:
if ((wParam = toupper (wParam)) == VK_RETURN)
wParam = '=' ;
if ((hButton = GetDlgItem (hWnd, wParam)) != NULL)
{
SendMessage (hButton, BM_SETSTATE, 1, 0L) ;
SendMessage (hButton, BM_SETSTATE, 0, 0L) ;
}
else
{
MessageBeep (0) ;
break ;
}
/* fall through */
case WM_COMMAND:
SetFocus (hWnd) ;
if (wParam == VK_BACK) /* backspace */
ShowNumber (hWnd, dwNumber /= 16) ;
else if (wParam == VK_ESCAPE) /* escape */
ShowNumber (hWnd, dwNumber = 0L) ;
else if (isxdigit (wParam)) /* hex digit */
{
if (bNewNumber)
{
dwFirstNum = dwNumber ;
dwNumber = 0L ;
}
bNewNumber = FALSE ;
if (dwNumber <= (ULONG_MAX >> 4))
ShowNumber (hWnd, dwNumber = 16 * dwNumber + wParam -
(isdigit (wParam) ? '0' : 'A' - 10)) ;
else
MessageBeep (0) ;
}
else /* operation */
{
if (!bNewNumber)
ShowNumber (hWnd, dwNumber =
CalcIt (dwFirstNum, nOperation, dwNumber)) ;
bNewNumber = TRUE ;
nOperation = wParam ;
}
break ;
case WM_DESTROY:
hWndCalc = NULL;
break;
default :
return DefWindowProc (hWnd, iMessage, wParam, lParam) ;
}
return 0L ;
}
/*===========================================================================*/
/* */
/* POPTEST.C - demonstration of the usage of floating popups */
/* */
/*===========================================================================*/
VOID DoFloatingPopup(VOID)
{
HMENU hMenu;
if ((hMenu = LoadMenu(hAppInstance, (LPSTR) "FloatingPopup")) != NULL)
TrackPopupMenu(GetSubMenu(hMenu,0), 0, MAKE_X(30),MAKE_Y(10), 0, hMain, 0);
}
/*===========================================================================*/
/* */
/* File : NOTEPAD.C */
/* */
/* Purpose : Demo of a multi-line edit field plus a new kind of button */
/* */
/*===========================================================================*/
#define MAXBUFSIZE 0xF000
static HWND hWndNotepad, hEdit;
static LPSTR pszFileToOpen = NULL;
int NotePad(VOID)
{
RECT r;
if (hWndNotepad)
{
BringWindowToTop(hWndNotepad);
SetFocus(hWndNotepad);
return TRUE;
}
hWndNotepad = CreateWindow("NotePad", /* class */
"NotePad", /* title */
WS_BORDER | WS_CAPTION | WS_SYSMENU |
WS_THICKFRAME | WS_VISIBLE,
MAKE_X(5), MAKE_Y(2),
MAKE_X(60), MAKE_Y(20),
hMain, /* hParent */
NULL, /* hMenu */
hAppInstance, /* hInst */
0L); /* lpParam */
GetClientRect(hWndNotepad, (LPRECT) &r);
hEdit = CreateWindow("Edit", /* class */
NULL, /* title */
ES_MULTILINE | WS_CHILD | WS_VISIBLE, /* dwStyle */
0,0,
CX_RECT(r), CY_RECT(r),
hWndNotepad, /* hParent */
0, /* hMenu */
hAppInstance, /* hInst */
0L); /* lpParam */
ShowWindow(hWndNotepad, SW_SHOW);
UpdateWindow(hWndNotepad);
BringWindowToTop(hWndNotepad);
SetFocus(hEdit);
return TRUE;
}
LONG FAR PASCAL NotepadWndProc(HWND hWnd, WORD message, WORD wParam, LONG lParam)
{
char buf[128];
HANDLE pHandle;
switch (message)
{
case WM_COMMAND :
switch (wParam)
{
case ID_EXIT:
hWndNotepad = NULL;
DestroyWindow(hWnd);
break;
case ID_CUT :
SendMessage(hEdit, WM_CUT, 0, 0L);
break;
case ID_CLEAR:
SendMessage(hEdit, WM_CLEAR, 0, 0L);
break;
case ID_COPY:
SendMessage(hEdit, WM_COPY, 0, 0L);
break;
case ID_PASTE:
SendMessage(hEdit, WM_PASTE, 0, 0L);
break;
case ID_GETLEN :
wsprintf(buf, "There are %d characters",
(int) SendMessage(hEdit, WM_GETTEXTLENGTH, 0, 0L));
MessageBox(hMain, buf, "Text Length", MB_OK);
break;
case ID_GETLINES:
wsprintf(buf, "There are %d lines",
(int) SendMessage(hEdit, EM_GETLINECOUNT, 0, 0L));
MessageBox(hMain, buf, "# of Lines", MB_OK);
break;
case ID_GETHANDLE:
pHandle = (HANDLE) SendMessage(hEdit, EM_GETHANDLE, 0, 0L);
wsprintf(buf, "The edit handle is [%x]", pHandle);
MessageBox(hMain, buf, "Get Handle", MB_OK);
break;
}
break;
case WM_SIZE :
MoveWindow(hEdit, 0, 0, LOWORD(lParam), HIWORD(lParam), TRUE);
break;
case WM_CLOSE :
hWndNotepad = NULL;
DestroyWindow(hWnd);
return TRUE;
default :
/* Call the default window procedure for the main window */
return DefWindowProc(hWnd, message, wParam, lParam);
}
return TRUE;
}
/*==========================================================================*/
/* */
/* Function : ComboDemo() */
/* */
/* Purpose : Shows all three styles of combo boxes */
/* */
/* Returns : */
/* */
/*==========================================================================*/
#define ID_CBFUTURES 1002
#define ID_CBEQUITIES 1003
#define ID_CBTICK 1004
VOID ComboDemo(void)
{
FARPROC lpfn;
MessageBox(hMain,
"To pulldown the hidden listbox portion of a combobox,\
click on the combobox arrow icon or press F4 or ALT-GREY-DOWN.",
"Combo box demo", MB_OK);
lpfn = MakeProcInstance((FARPROC) ComboDialogProc, hAppInstance);
DialogBox(hAppInstance, "UpdateSettings", hMain, lpfn);
FreeProcInstance(lpfn);
}
int FAR PASCAL ComboDialogProc(HWND hDlg, WORD msg, WORD wParam, DWORD lParam)
{
int i;
static char *szColors[] =
{
"Black", "Blue", "Green", "Cyan",
"Red", "Magenta", "Yellow", "White",
NULL
};
(void) lParam;
switch (msg)
{
case WM_INITDIALOG :
SendDlgItemMessage(hDlg, ID_CBTICK, WM_SETREDRAW, FALSE, 0L);
for (i = 0; szColors[i]; i++)
SendDlgItemMessage(hDlg, ID_CBTICK, CB_ADDSTRING, 0, (DWORD) (LPSTR) szColors[i]);
SendDlgItemMessage(hDlg, ID_CBTICK, CB_SETCURSEL, 2, 0L);
i = (int) SendDlgItemMessage(hDlg, ID_CBTICK, CB_GETCURSEL, 0, 0L);
SendDlgItemMessage(hDlg, ID_CBTICK, WM_SETREDRAW, TRUE, 0L);
SendDlgItemMessage(hDlg, ID_CBFUTURES, WM_SETREDRAW, FALSE, 0L);
for (i = 0; szColors[i]; i++)
SendDlgItemMessage(hDlg, ID_CBFUTURES, CB_ADDSTRING, 0, (DWORD) (LPSTR) szColors[i]);
SendDlgItemMessage(hDlg, ID_CBFUTURES, CB_SETCURSEL, 6, 0L);
i = (int) SendDlgItemMessage(hDlg, ID_CBFUTURES, CB_GETCURSEL, 0, 0L);
SendDlgItemMessage(hDlg, ID_CBFUTURES, WM_SETREDRAW, TRUE, 0L);
SendDlgItemMessage(hDlg, ID_CBEQUITIES, WM_SETREDRAW, FALSE, 0L);
for (i = 0; szColors[i]; i++)
SendDlgItemMessage(hDlg, ID_CBEQUITIES, CB_ADDSTRING, 0, (DWORD) (LPSTR) szColors[i]);
SendDlgItemMessage(hDlg, ID_CBEQUITIES, CB_SETCURSEL, 2, 0L);
i = (int) SendDlgItemMessage(hDlg, ID_CBEQUITIES, CB_GETCURSEL, 0, 0L);
SendDlgItemMessage(hDlg, ID_CBEQUITIES, WM_SETREDRAW, TRUE, 0L);
return TRUE;
case WM_COMMAND :
switch (wParam)
{
case IDOK :
case IDCANCEL :
EndDialog(hDlg, TRUE);
break;
}
return TRUE;
}
return FALSE;
}